package com.zb.user.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.SelectVo;
import com.zb.result.Result;
import com.zb.service.ZjUserLevelService;
import com.zb.utils.TokenUtil;
import com.zb.vo.UserLevelSelectVo;
import com.zb.vo.UserLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 用户等级表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-08-08
 */
@Api(tags = "用户级别类接口")
@RestController
@RequestMapping("/user/level")
public class ZjUserLevelController {
    @Resource
    private ZjUserLevelService userLevelService;

    @SystemLog(moduleType = OperationLogModuleType.USER_MODULE_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "用户档案 - 新增或修改用户级别")
    @ApiOperation("新增或修改用户级别")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid UserLevelVo userLevelVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        userLevelService.save(custAccId, userLevelVo);
        return Result.success(null == userLevelVo.getId()? "新增级别成功" : "修改级别成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.USER_MODULE_TYPE, type = OperationLogType.SELECT, remark = "用户档案 - 获取用户级别列表")
    @ApiOperation("获取用户级别列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody UserLevelSelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取级别列表成功！").data(userLevelService.getList(custAccId, selectVo));
    }

    @SystemLog(moduleType = OperationLogModuleType.USER_MODULE_TYPE, type = OperationLogType.UPDATE, remark = "用户档案 - 批量更改用户级别状态")
    @ApiOperation("批量更改用户级别状态")
    @PutMapping("/")
    public Result disable(@RequestParam @ApiParam(value = "级别状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "级别ID集合", required = true) List<Long> idList) {
        userLevelService.updateBatchDisabledByIds(idList, status);
        return Result.success(status? "禁用级别成功" : "启用级别成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.USER_MODULE_TYPE, type = OperationLogType.DELETE, remark = "用户档案 - 批量删除用户级别状态")
    @ApiOperation("批量删除用户级别状态")
    @DeleteMapping("/")
    public Result delete(@RequestBody @ApiParam(value = "级别ID集合", required = true) List<Long> idList) {
        userLevelService.deleteBatchByIds(idList);
        return Result.success("删除成功");
    }


}
